package org.dromara.system.controller.api;

import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.utils.MapstructUtils;
import org.dromara.system.api.domain.vo.RemoteTenantVo;
import org.dromara.system.domain.bo.SysTenantBo;
import org.dromara.system.domain.vo.SysTenantVo;
import org.dromara.system.service.ISysTenantService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author: zhou shuai
 * @date: 2024/9/26 20:31
 * @version: v1
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/system/tenant")
public class SysTenantApiController {

    private final ISysTenantService tenantService;

    /**
     * 根据租户id获取租户详情
     */
    @GetMapping("/{tenantId}")
    public R<RemoteTenantVo> queryByTenantId(@PathVariable("tenantId") String tenantId) {
        SysTenantVo vo = tenantService.queryByTenantId(tenantId);
        RemoteTenantVo remoteTenantVo = MapstructUtils.convert(vo, RemoteTenantVo.class);
        return R.ok(remoteTenantVo);
    }

    /**
     * 获取租户列表
     */
    @GetMapping("/list")
    public R<List<RemoteTenantVo>> queryTenantList() {
        List<SysTenantVo> list = tenantService.queryList(new SysTenantBo());
        List<RemoteTenantVo> remoteTenantVoList = MapstructUtils.convert(list, RemoteTenantVo.class);
        return R.ok(remoteTenantVoList);
    }

}
